import { Router } from 'express'
import authController from '../controllers/auth.js'
import profileController from '../controllers/profile.js'
import authMiddleware from '../middleware/auth.js'
import multer from 'multer'

const upload = multer({ dest: 'uploads/avatar/' })
const coverUpload = multer({ dest: 'uploads/cover/' })

const router = Router()

// 认证路由
router.post('/login', authController.login)
router.post('/register', authController.register)

// 用户资料路由
router.get('/profile', authMiddleware, profileController.getProfile)
router.put('/profile', authMiddleware, profileController.updateProfile)

// 文件上传路由
router.post('/upload/avatar', authMiddleware, upload.single('avatar'), (req, res) => {
  // 简单的文件上传处理
  if (req.file) {
    res.json({
      success: true,
      message: '头像上传成功',
      data: { filename: req.file.filename }
    })
  } else {
    res.status(400).json({
      success: false,
      message: '请选择要上传的文件'
    })
  }
})

router.post('/upload/cover', authMiddleware, coverUpload.single('cover'), (req, res) => {
  // 简单的文件上传处理
  if (req.file) {
    res.json({
      success: true,
      message: '封面图片上传成功',
      data: { filename: req.file.filename }
    })
  } else {
    res.status(400).json({
      success: false,
      message: '请选择要上传的文件'
    })
  }
})

export default router 